//
//  AddMeterRemarkParamCell.swift
//  Employee
//
//  Created by tancheng on 2018/6/22.
//  Copyright © 2018年 remotevillage. All rights reserved.
//

import UIKit
import YYText
import IQKeyboardManager

class AddMeterRemarkParamCell: UITableViewCell,YYTextViewDelegate {

    static let reuseIdentifer = "AddMeterRemarkParamCell"

    @IBOutlet weak var subContentView: UIView!
    
    var beginEidtingBlock:(()->())?
    var didEidtedBlock:((String)->())?
    
    lazy var textView: YYTextView = {
        let tv = YYTextView()
        tv.font = UIFont.systemFont(ofSize: 16)
        tv.textColor = GlobalConfig.TextDeepColor
        tv.placeholderText = "点击输入"
        tv.placeholderTextColor = UIColor.hex("#323C49", alpha: 0.5)
        tv.textAlignment = .left
        tv.delegate = self
        
        return tv
    }()
    
    var paramModel: AddMeterModel? {
        didSet {
            
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        subContentView.addSubview(textView)
        textView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(62)
            make.left.equalToSuperview().offset(40)
            make.right.equalToSuperview().offset(-40)
            make.bottom.equalToSuperview().offset(-20)
        }
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    //
    
    func textView(_ textView: YYTextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
        print(text)
        let inText: String = text + textView.text
        if inText.count > 200 {
            textView.text = inText.sj.cut(to: 200)
            return false
        }
        return true
    }
    
    func textViewShouldBeginEditing(_ textView: YYTextView) -> Bool {
        self.beginEidtingBlock?()
        
        return true
    }
    
    func textViewDidEndEditing(_ textView: YYTextView) {
        self.didEidtedBlock?(textView.text)
    }
 
}
